package com.mofum.scope.controller;

import com.mofum.scope.annotation.controller.QueryScope;
import com.mofum.scope.annotation.controller.ServiceColumn;
import com.mofum.scope.annotation.controller.UpdateScope;
import com.mofum.scope.dto.UserDto;
import com.mofum.scope.entity.Page;
import com.mofum.scope.entity.User;
import com.mofum.scope.service.IUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author developer@omuao.com
 * @since 2019-03-28
 **/
@RestController
@RequestMapping("/user")
public class UserController extends ScopeController {

    public static Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    IUserService userService;

    @RequestMapping("/add")
    public Object addUser(User user) {
        userService.addUser(user);
        return "SUCCESS";
    }

    @RequestMapping("/query")
    public Object query(UserDto userDto) {
        logger.info(userDto.toString());
        return userService.queryUser(userDto, Page.PAGE_ONE);
    }

    @RequestMapping("/scope/query")
    @QueryScope
    public Object scopeQuery(UserDto userDto) {
        logger.info(userDto.toString());
        return userService.queryUser(userDto, Page.PAGE_ONE);
    }

    @RequestMapping("/del")
    @UpdateScope(columns = {
            @ServiceColumn(value = "serviceIds"),
            @ServiceColumn(value = "ids", type = "P_SHOP", array = true, json = true)
    })
    public Object del(UserDto userDto, String ids) {
        logger.info(userDto.toString());
        return "SUCCESS";
    }
}
